﻿@{
    IEnumerable<Notice> notices = ViewData["notices"] as IEnumerable<Notice>;

    string ids = string.Empty;
    if (notices != null)
    {
        foreach (var notice in notices)
        {
            ids += (notice.Id + ",");
        }
    }
}
<div id="promp_notice" class="tnc-prompt-wrap tn-border-gray tn-border-bottom">
    @{
        if (notices != null)
        {
        <h3 class="tn-helper-reset tnc-prompt-header">
            通知</h3>
        <ul class="tn-list">
            @foreach (var notice in notices)
            {
                if (string.IsNullOrEmpty(notice.ResolvedBody))
                {
                    continue;
                }
                <li id="notice_@(notice.Id)"  class="tn-list-item"><span name="operate_@(notice.Id)" class="tnc-handle-mark">@Html.Link("知道了", SiteUrls.Instance().BatchSetIsHandled(UserContext.CurrentUser.UserName, notice.Id.ToString()), "知道了", new { id = "promp-item-notice-" + notice.Id, @Class = "tn-icon tn-smallicon-cross" })</span>
                    @Html.Raw(notice.ResolvedBody)
                </li>
            }
        </ul>
        <div class="tn-actions">
            <div class="tn-confirm">
                @Html.LinkButton("我全知道了", SiteUrls.Instance().BatchSetIsHandled(Url.SpaceKey(), ids), HighlightStyles.Primary, htmlAttributes: new { id = "promp-all-notice" })
            </div>
            <div class="tn-view">
                @Html.LinkButton("查看所有", SiteUrls.Instance().ListNotices(Url.SpaceKey(), NoticeStatus.Unhandled, 1), HighlightStyles.Secondary)
            </div>
        </div>
        }
    }
</div>
<script type="text/javascript" language="javascript">
    $(document).ready(function () {
        $("li[id^='notice_'] a:not([id^='promp-item-notice-'],[plugin])").click(function () {
            var url = $(this).attr("href");
            var $SetIsHandled = $(this).parents("li[id^='notice_']").find("a[id^='promp-item-notice-']:first");
            $.post($SetIsHandled.attr("href"), function (data) {
                if (data)
                    window.location.href = url;
            });
            return false;
        });
    });
</script>
